package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BibliotecaApp {

    public static void main(String[] args) throws IOException {
        Library Lib= new Library();
        int selection,BookNo,MovieId;
        User U;
        InputStreamReader istream = new InputStreamReader(System.in);
        BufferedReader bufRead = new BufferedReader(istream);
        System.out.println("=============================");
        System.out.println("=     Welcome to the        =");
        System.out.println("=        Biblioteca         =");
        System.out.println("= Library Management System =");
        System.out.println("=============================\n");
        while (true) {
            System.out.println("Press Enter To Continue");
            bufRead.readLine();

            Runtime.getRuntime().exec("clear");
            System.out.println("Menu:");
            System.out.println("1) View all books");
            System.out.println("2) View all available books");
            System.out.println("3) Checkout a book");
            System.out.println("4) Return a book");

            System.out.println("5) View all Movies");
            System.out.println("6) View all available Movie");
            System.out.println("7) Checkout a Movie");
            System.out.println("8) Return a Movie");
            System.out.println("9) View Card Holders");
            System.out.println("10) Quit");
            System.out.println("Enter an option:- ");
            selection = Integer.parseInt(bufRead.readLine());

            switch (selection) {
                case 1:
                    Lib.ViewAllBooks();
                    break;
                case 2:
                    Lib.ViewAvailableBookList();
                    break;
                case 3:
                    Lib.ViewAvailableBookList();
                    System.out.println("Enter Book No To Checkout");
                    BookNo = Integer.parseInt(bufRead.readLine());
                    U=Lib.UserLogin();
                    Lib.CheckOutBook(BookNo,U);
                    break;
                case 4:
                    Lib.ViewAllBooks();
                    System.out.println("Enter Book No To Return");
                    BookNo = Integer.parseInt(bufRead.readLine());
                    U=Lib.UserLogin();
                    Lib.ReturnBook(BookNo,U);
                    break;
                case 5:
                    Lib.ViewAllMovies();
                    break;
                case 6:
                    Lib.ViewAvailableMovieList();
                    break;
                case 7:
                    Lib.ViewAvailableMovieList();
                    System.out.println("Enter Movie Id To Checkout");
                    MovieId = Integer.parseInt(bufRead.readLine());
                    U=Lib.UserLogin();
                    Lib.CheckOutMovie(MovieId,U);
                    break;
                case 8:
                    Lib.ViewAllMovies();
                    System.out.println("Enter Movie Id To Return");
                    MovieId = Integer.parseInt(bufRead.readLine());
                    U=Lib.UserLogin();
                    Lib.ReturnMovie(MovieId,U);
                    break;
                case 9:
                    Lib.ViewAllUsers();
                    break;

                case 10:
                    System.exit(1);
                default:
                    System.out.println("Invalid Choice!!");
            }
        }

    }

}
